import { HYEventStore } from 'hy-event-store';
import { getRanking } from '../service/api_music';
const rankingMap = {
  0: 'newRanking',
  1: 'hotRanking',
  2: 'originRanking',
  3: 'upRanking',
};
const rangkingStore = new HYEventStore({
  state: {
    newRanking: {},
    hotRanking: {},
    originRanking: {},
    upRanking: {},
  },
  actions: {
    // 0：新歌榜、1:热歌榜、2：原创榜、3：飙升榜
    getRankingDataAcion(state) {
      for (let i = 0; i < 4; i++) {
        getRanking(i).then(res => {
          const rankingName = rankingMap[i];
          state[rankingName] = res.playlist;
          // switch (i) {
          //     case 0:
          //         state.newRanking = res.playlist
          //         break;
          //     case 1:
          //         state.hotRanking = res.playlist
          //         break;
          //     case 2:
          //         state.originRanking = res.playlist
          //         break;
          //     case 3:
          //         state.upRanking = res.playlist
          //         break;
          //     default:
          //         return
          // }
        });
      }
    },
  },
});

export { rangkingStore, rankingMap };
